from django.db import models


class Category(models.Model):
    name = models.CharField(max_length=30)
    cid = models.ForeignKey('self', related_name='subs', on_delete=models.CASCADE, null=True, blank=True)

    class Meta:
        db_table = 'category'

    def __str__(self):
        return self.name


class Group(models.Model):

    name = models.CharField("分类分组", max_length=30)
    # 一级类别
    cate = models.OneToOneField(Category, on_delete=models.CASCADE)
    group_url = models.CharField("频道的地址链接", max_length=100, default="http://jd.com")
    sequence = models.IntegerField(verbose_name="组内的顺序", default=0)

    class Meta:
        db_table = 'cate_group' # 不能使用group命名，会导致sql操作失败。

    def __str__(self):
        return self.name












